package com.hfdg.prototype.base.generator;

import com.hfdg.prototype.base.annotations.Column;
import com.hfdg.prototype.base.utils.CamelUtils;

import java.lang.reflect.Field;

/**
 * @ClassName ColumnField
 * @Description TODO 实体类字段与数据库字段映射关系
 * @Author yuelh
 * @Date 2019/1/18 19:43
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
public class ColumnField {
    String column;
    String property;
    String jdbcType;
    String javaType;
    public String getColumn() {
        return column;
    }
    public void setColumn(String column) {
        this.column = column;
    }
    public String getProperty() {
        return property;
    }
    public void setProperty(String property) {
        this.property = property;
    }
    public String getJdbcType() {
        return jdbcType;
    }
    public void setJdbcType(String jdbcType) {
        this.jdbcType = jdbcType;
    }
    public String getJavaType() {
        return javaType;
    }
    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }
    public static ColumnField build(Field field){
        ColumnField cf = new ColumnField();
        cf.setColumn(CamelUtils.camel2Underline(field.getName()));
        cf.setProperty(field.getName());
        cf.setJavaType(field.getType().getName());
        if(null!=field.getAnnotation(Column.class)){
            cf.setJdbcType(field.getAnnotation(Column.class).type().getName());
        }else{
            cf.setJdbcType("VARCHAR");
        }
        return cf;
    }
}
